/****************************************************
    
	Master Do-File for Ghosh, Hwang, Squires (2023)
	Economic consequences of kinship: Evidence from
	U.S. bans on cousin marriage

    This do-file replicates all Tables and Figures
    in the paper. Do-files that use restricted-data
	have been commented out.

****************************************************/

scalar t1 = c(current_time)
di t1

* Please change the global dir to where the folder is saved on your computer
if "`c(username)'" == "Deaglan Jakob" {
	global dir "C:\Users\Deaglan Jakob\Dropbox\GHS_CM_Replication"
} 
else if "`c(username)'" == "munirsquires" {
	global dir "/Users/munirsquires/Dropbox/GHS_CM_Replication"
} 
else if "`c(username)'" == "ag734" {
	global dir "/Users/ag734/Dropbox/GHS_CM_Replication"
}

cd "$dir"

cap mkdir "$dir/Output"
cap mkdir "$dir/Output/TablesFigures"
global outdir "$dir/Output/TablesFigures"


* Packages required to be installed
cap ssc install nysiis
cap ssc install maptile
cap ssc install reghdfe
cap ssc install eventstudyinteract
cap ssc install event_plot
cap ssc install erepost
cap ssc install spmap
cap ssc install blindschemes 
cap ssc install binscatter
cap ssc install dmout
cap ssc install scheme-burd
cap ssc install estout
cap ssc install ftools
cap ssc install avar

clear all
set segmentsize 3g
set scheme plotplainblind

******************************
******** Prepare Data ********
******************************

* 1.Prepare Data
//do "$dir/Code/01 Prep/1_Create_CM"
//do "$dir/Code/01 Prep/2_OLS_PrepareAnalysis"
//do "$dir/Code/01 Prep/3_EventStudy_PrepareAnalysis"


**************************
******** Analysis ********
**************************

** 2.Summary Stats **
do "$dir/Code/02 Analysis/Descriptives/1_prepostCM_persistence"
do "$dir/Code/02 Analysis/Descriptives/2_CM_Rates_Maps"
do "$dir/Code/02 Analysis/Descriptives/3_MarriageRecords_Coverage"
do "$dir/Code/02 Analysis/Descriptives/4_consanguinity_income"
do "$dir/Code/02 Analysis/Descriptives/5_FCM_Isonymy_SY"
do "$dir/Code/02 Analysis/Descriptives/6_IsoCM"
//do "$dir/Code/02 Analysis/Descriptives/7_BalanceTable_MRCensus_linkedvsnot"
do "$dir/Code/02 Analysis/Descriptives/8_earlyvslate_ban"


** 3.OLS Regressions **
//do "$dir/Code/02 Analysis/OLS/1_LinkedCensusMR_OLS"


** 4.Event Study Regressions **
do "$dir/Code/02 Analysis/Event-Study/1_CM_FiguresTables_FirstStage"
do "$dir/Code/02 Analysis/Event-Study/2_CM_FiguresTables_MainResults"
do "$dir/Code/02 Analysis/Event-Study/3_CM_FiguresTables_AgeMSHet"
do "$dir/Code/02 Analysis/Event-Study/4_CM_FiguresTables_WealthHet"
do "$dir/Code/02 Analysis/Event-Study/5_CM_TablesRobustness_Confounders"
do "$dir/Code/02 Analysis/Event-Study/6_CM_TablesRobustness_FBPLTreatment"
do "$dir/Code/02 Analysis/Event-Study/7_CM_TablesRobustness_NYSIIS_Surnames"
do "$dir/Code/02 Analysis/Event-Study/8_CM_TablesRobustness_StatesurnameCM"
//do "$dir/Code/02Analysis/Event-Study/9_CM_TablesRobustness_Surnamestatesize_controls"
do "$dir/Code/02 Analysis/Event-Study/10_CM_TablesRobustness_8pthresh"
do "$dir/Code/02 Analysis/Event-Study/11_CM_TablesRobustness_12pthresh"
do "$dir/Code/02 Analysis/Event-Study/12_CM_TablesRobustness_ObsIsonymy"
//do "$dir/Code/02 Analysis/Event-Study/13_CM_TablesRobustness_SFE"
do "$dir/Code/02 Analysis/Event-Study/14_CM_TablesRobustness_LastTreatedControl"
do "$dir/Code/02 Analysis/Event-Study/15_CM_TablesRobustness_CommUncomm_Surnames"


** 5.Familinx and Isonymy **
do "$dir/Code/02 Analysis/Familinx_MR/1_geni_isonymy"
do "$dir/Code/02 Analysis/Familinx_MR/2_geni_fs"
do "$dir/Code/02 Analysis/Familinx_MR/3_fcm_types"


scalar t2 = c(current_time)
di t2
